package com.link.base.base.pocdataimport.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.link.core.basic.annotations.JsonParam;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.link.base.base.pocdataimport.model.PocDataImport;
import com.link.base.base.pocdataimport.service.PocDataImportService;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * poc数据导入-没有其他项目可选，暂时选择青啤 
 *
 * @author 郭闪
 * @date 2020/04/03 16:30
 */
@Controller
@RequestMapping("/link/pocDataImport")
public class PocDataImportController extends BasicController<PocDataImport> {
 
    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private PocDataImportService pocDataImportService;

    @Override
    public BasicService<PocDataImport> getBasicService() throws Exception {
        return pocDataImportService;
    }

    /**
     * 校验导入数据的正确性
     * @author 谢育强
     * @date 2020-0404
     */
    @RequestMapping(value = "/checkImportData", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> checkImportData(@JsonParam PocDataImport entity, HttpSession session,
                                               HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            pocDataImportService.checkImportData();
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 确认将校验成功的数据拆分
     * @author 谢育强
     * @date 2020-0404
     */
    @RequestMapping(value = "/confirmImportData", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> confirmImportData(@JsonParam PocDataImport entity, HttpSession session,
                                               HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            pocDataImportService.confirmImportData();
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
